<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Page load</title>
</head>
<body>
<div id="result"></div>
<div style="background-color: #6ab779; width: 100px; height: 100px;;"></div>
<script>
    const currentDialogItemName = 'currentDialog';
    const promptResultItem      = 'promptResult';
    const confirmResultItem     = 'confirmResult';
    const geolocationResultItem = 'geoResult';

    const dialogs       = {
        alert:       'alert',
        confirm:     'confirm',
        prompt:      'prompt',
        print:       'print',
        geolocation: 'geolocation',
    };
    const dialogsOrder  = [
        dialogs.alert,
        dialogs.confirm,
        dialogs.prompt,
        dialogs.print,
        dialogs.geolocation,
    ];
    const currentDialog = sessionStorage.getItem(currentDialogItemName) || dialogsOrder[0];

    function getNextDialog (currentDialog) {
        return dialogsOrder[dialogsOrder.indexOf(currentDialog) + 1];
    }

    window.getDialogsResult = () => {
        return {
            prompt:      sessionStorage.getItem(promptResultItem),
            confirm:     sessionStorage.getItem(confirmResultItem),
            geolocation: sessionStorage.getItem(geolocationResultItem),
        };
    };

    sessionStorage.setItem(currentDialogItemName, getNextDialog(currentDialog));

    if (currentDialog === dialogs.alert) {
        alert('Alert!');
        document.location.reload();
    }
    else if (currentDialog === dialogs.confirm) {
        sessionStorage.setItem(confirmResultItem, window.confirm('Confirm?'));
        document.location.reload();
    }
    else if (currentDialog === dialogs.prompt) {
        sessionStorage.setItem(promptResultItem, window.prompt('Prompt'));
        document.location.reload();
    }
    else if (currentDialog === dialogs.print) {
        window.print();
        document.location.reload();
    }
    else if (currentDialog === dialogs.geolocation) {
        window.navigator.geolocation.getCurrentPosition(geo => sessionStorage.setItem(geolocationResultItem, JSON.stringify(geo)));
        sessionStorage.removeItem(currentDialogItemName);
    }
</script>
</body>
</html>
